package com.itbaizhan.service.impl;

import com.itbaizhan.api.AddUserService;
import com.itbaizhan.api.DeleteUserService;
import com.itbaizhan.api.FindUserAll;
import com.itbaizhan.api.UpdateUserService;
import com.itbaizhan.pojo.User;
import com.itbaizhan.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service //springBoot 类
public class UserServiceImpl implements UserService {

    //远程调用provider层 先含有dubbo类导入
    // 调用user_api的接口，provider层又实现了user_api接口
    //生产者层才连接数据库，所以必须调用生产者层
    @Reference
    AddUserService addUserService;
    @Reference
    FindUserAll findUserAll;
    @Reference
    UpdateUserService updateUserService;
    @Reference
    DeleteUserService deleteUserService;
    //添加用户
    @Override
    public int addUser(User user) {
        return addUserService.addUser(user);
    }

    //查询所有用户
    @Override
    public List<User> findAll() {
        return findUserAll.findUserAll();
    }

    @Override
    public User findById(Long id) {
        return updateUserService.selectByid(id);
    }

    @Override
    public void updateUser(User user) {
        updateUserService.updateUser(user);
    }

    @Override
    public void deleteUserById(Long id) {
        deleteUserService.deleteByUserId(id);
    }
}
